//
//  LabelWithDottedlineCellData.m
//  18Birdies
//
//  Created by poleness on 2017/7/6.
//  Copyright © 2017年 Lc. All rights reserved.
//

#import "LabelWithDottedlineCellData.h"
#import "LabelWithDottedlineCell.h"

@implementation LabelWithDottedlineCellData

+ (instancetype)cellDataWithTitle:(NSString*)title
                       rightTitle:(NSString*)rightTitle
      onRightButtonClickedHandler:(OnClickedHandler)onRightButtonClickedHandler {
  return [self cellDataWithTitle:title
                       rightTitle:rightTitle
                     showIndicate:NO
                   showDottedLine:YES
      onRightButtonClickedHandler:onRightButtonClickedHandler];
}

+ (instancetype)cellDataWithTitle:(NSString*)title showIndicate:(BOOL)showIndicate {
  return [self cellDataWithTitle:title showIndicate:showIndicate showDottedLine:YES];
}
+ (instancetype)cellDataWithTitle:(NSString*)title
                     showIndicate:(BOOL)showIndicate
                   showDottedLine:(BOOL)showDottedLine {
  return [self cellDataWithTitle:title
                       rightTitle:nil
                     showIndicate:showIndicate
                   showDottedLine:showDottedLine
      onRightButtonClickedHandler:nil];
}

+ (instancetype)cellDataWithTitle:(NSString*)title
                       rightTitle:(NSString*)rightTitle
                     showIndicate:(BOOL)showIndicate
                   showDottedLine:(BOOL)showDottedLine
      onRightButtonClickedHandler:(OnClickedHandler)onRightButtonClickedHandler {
  LC_CHECK_TRUE(rightTitle.length == 0 || !showIndicate);
  LabelWithDottedlineCellData* cellData = [[LabelWithDottedlineCellData alloc] init];
  cellData.title = title;
  cellData.rightTitle = rightTitle;
  cellData.showIndicate = showIndicate;
  cellData.showDottedLine = showDottedLine;
  cellData.cellHeight = 44;
  cellData.clickable = NO;
  cellData.onRightButtonClickedHandler = onRightButtonClickedHandler;
  return cellData;
}

- (Class)cellClazz {
  return LabelWithDottedlineCell.class;
}

- (NSString*)nibName {
  return @"LabelWithDottedlineCell";
}

- (void)refreshCell:(LabelWithDottedlineCell*)cell {
  [super refreshCell:cell];
  cell.leftLabel.text = self.title;
  [cell.rightButton setTitle:self.rightTitle];
  cell.rightButton.hidden = self.rightTitle.length == 0;
  cell.indicateImageView.hidden = !self.showIndicate;
  cell.dottedLineImageView.hidden = !self.showDottedLine;
  cell.onRightButtonClickedHandler = self.onRightButtonClickedHandler;

  if (self.titleFont != nil) {
    [cell.leftLabel setLcFont:self.titleFont];
  }
  if (self.rightTitleFont != nil) {
    [cell.rightButton setLcFont:self.rightTitleFont];
  }
  if (self.backgroundColor != nil) {
    cell.backgroundColor = self.backgroundColor;
  }
}

@end
